package screen;


import javax.microedition.lcdui.Graphics;

import font.BitmapFont;

import utilities.GameResource;
import utilities.TField;

import main.GameCanvas;
import model.Command;
import model.IAction;

public class InputDlg extends Dialog {
	protected String[] info;
	public TField tfInput;
	public IAction okAction;
	public IAction backAction;
	
	public InputDlg() {
		tfInput = new TField();
		
		tfInput.isFocus = true;
		right = tfInput.cmdClear;
	}
	
	public void setInfo(String info, IAction ok,  int type) {
		tfInput.setText("");
		tfInput.setIputType(type);
		this.info = BitmapFont.m_bmNormalFont.splitFontBStrInLine(info, GameCanvas.w - 40);
		this.okAction = ok;
		
		this.backAction = new IAction(){
			public void perform(){
				GameCanvas.endDlg();
			}
		};
		left = new Command(GameResource.close, backAction);
		center = new Command(GameResource.OK, okAction);
		
		
		
		tfInput.x = GameCanvas.hw - 40;
		tfInput.y = GameCanvas.h - 48;
		tfInput.width = 80;
		tfInput.height = Screen.ITEM_HEIGHT + 2;
		
		
	}
	public void paint(Graphics g) {	
		
		PaintPopup.paintBox(g, GameCanvas.hw - 55, GameCanvas.h - 87, 120, 69);
		int i, y;
		int yStart = GameCanvas.h - 35 - 50 - ((info.length >> 1) * BitmapFont.m_bmNormalFont.getHeight());
		for (i = 0, y = yStart; i < info.length; i++, y += BitmapFont.m_bmNormalFont.getHeight()) {
			BitmapFont.drawNormalFont(g, info[i], GameCanvas.hw, y + 15, 0xffff00, Graphics.HCENTER | Graphics.VCENTER);
		}
		
		tfInput.y = GameCanvas.h - 48;
		tfInput.paint(g);
						
		super.paint(g);
	}	
	public void keyPress(int keyCode) {
		tfInput.keyPressed(keyCode);
		
		
		super.keyPress(keyCode);
	}

	public void update() {
		tfInput.update();
		super.update();
	}

	public void show() {
		GameCanvas.currentDialog = this;
	}
}
